<%@ page contentType="text/html; charset=utf-8" %>
<%@ include file="/WEB-INF/jsp/includeTaglib.jsp" %>


<form id="projectStoreForm">
	<input type="hidden" name="projectId" value="${projectId}" />
	<%@ include file="/WEB-INF/jsp/project/projectStoresSearch.jsp" %>
</form>

<table class="globalText" border="0" cellpadding="0" cellspacing="2">
	<tr>
		
		<td><input type="button" class="btnStyle" value=" 添加门店 " onclick="var a=window.showModalDialog('<c:url value="/channelList.html"/>',window,'status:no;resizable:no;directories:no;help:no;scroll:no;dialogWidth=800px;dialogHeight=450px;dialogLeft:500px;dialogTop:300px;');"></td>
	</tr>
</table>
<div id="projectStoresListData" class="pageDiv">
						       	
</div>


<form target="tempFrame" id="addProjectStoreForm" action="<c:url value='/project/editProjectStores.html' />">
	<input type="hidden" name="projectId" value="${projectId}" />
	<input type="hidden" name="storesId" id="storesId" />
</form>

<script>
	
	listDefaultPageAjax('projectStoresListData','projectStoreForm','<c:url value='/project/projectStoresList.html' />');
	
	var addStoreIds=new Array();
	<c:forEach var="ids" items="${storeIds}" varStatus="status">
		addStoreIds.push('${ids}');
	</c:forEach>
	
	function channelListOnloadCallBack(subWindow){
		var subDocument=subWindow.document;
		$(subDocument).find('.chooseBtn').each(function(i){
			$(this).hide();
		});
		
		$(subDocument).find('.checkBoxS').each(function(i){
			$(this).show();
			var code=$(this).attr("channelCheckBoxCode");
			for(var i=0;i<addStoreIds.length;i++){
				if(code==addStoreIds[i]){
					//$(this).attr("checked",true);
					//$(this).attr("disabled",true);
				}
			}
		});
		
		var addButton=$('#addChannelBtn').clone("true");
		var closeChannelBtn=$('#closeChannelBtn').clone("true");
		
		closeChannelBtn.bind("click",function(){
			subWindow.close();
		});
		
		addButton.bind("click",function(){
			var storesId="";
			$(subDocument).find('.checkBoxS').each(function(i){
				if($(this).attr("checked") && !$(this).attr("disabled")){
					storesId+=$(this).attr("channelCheckBoxCode")+";";
					$(this).attr("disabled",true);
				}
			});
			
			if(storesId==""){
				subWindow.alert("未选择通路信息");
			}else{
				$('#storesId').val(storesId);
				$('#addProjectStoreForm').submit();
				subWindow.close();
			}
		});
		
		
		$(subDocument).find('#paginationBlock').after(closeChannelBtn);
		$(subDocument).find('#paginationBlock').after(addButton);
		
	}
	
	function submitCallbackSuccess(obj){
		listDefaultPageAjax('projectStoresListData','projectStoreForm','<c:url value='/project/projectStoresList.html' />');
	}
</script>

<div style="display: none;">
	<span><input id="addChannelBtn" type="button" class="btnStyle" value=" 添加 " /></span>
	<span><input id="closeChannelBtn" type="button" class="btnStyle" value=" 关闭" /></span>
</div>
